package com.immunology.servlets;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.immunology.model.MappingPages;
import com.immunology.model.Syndrome;
import com.immunology.service.SyndromeService;

public class EditSyndromeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public EditSyndromeServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		getServletContext()
		.getRequestDispatcher(MappingPages.SHOW_SYNDROME_JSP).forward(
				request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		String syndromeName = request.getParameter("syndromeName");
		@SuppressWarnings("unchecked")
		Enumeration<String> enumeration = request.getParameterNames();
		int syndromeId = Integer.parseInt(enumeration.nextElement());
		SyndromeService syndromeService = SyndromeService.getInstance();
		Syndrome syndrome = syndromeService.getSyndromeById(syndromeId);
		syndrome.setName(syndromeName);
		syndromeService.update(syndromeId,syndrome);
		getServletContext()
				.getRequestDispatcher(MappingPages.SHOW_SYNDROME_JSP).forward(
						request, response);
	}

}
